<template>
  <div>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item v-for="item in arr" :key="item.path">{{ item.title }}</el-breadcrumb-item>
    </el-breadcrumb>
  </div>
</template>

<script setup>
import { watch, ref, computed } from "vue";
import { useRoute } from "vue-router";

const route = useRoute();

const breadCrumbArr = ref([]);

watch(
  route,
  (val) => {
    if (val.path !== '/home' && val.name !== 'NotFound') {
      breadCrumbArr.value = val.meta.breadCrumb
    } else {
      breadCrumbArr.value = []
    }
  },
  { immediate: true }
);

const arr = computed(() => {
  return breadCrumbArr.value.slice().reverse()
})
</script>

<style lang="less" scoped>
.el-breadcrumb {
  line-height: 50px;
  margin-left: 10px;
}
</style>
